<div id='breadcrumb'>
  <%=  breadcrumb_for_category(@category)%>
</div>
<div id="product_list_title">
  <% if @brand %>
    <%= image_tag url_for_file_column(@brand,"image_url","thumb") if @brand.image_url %>
    <%=@brand.name%>
  <%  end %>
  <%=h truncate(@category.name,100) %>
</div>

<% if @brands && @brands.length > 0 %>
  <h2 class="category_list_title">按品牌选择</h2>
  <ul class="brand_list">
    <% for b in @brands %>
      <li class="brand_title">

        <div class="brand_img_wrapper">
          <a href="/categories/<%= params[:id] %>?brand_id=<%= b.id %>">
            <%= image_tag url_for_file_column(b,"image_url","thumb") if b.image_url %>
          </a>
        </div>
        <div>
          <a href="/categories/<%= params[:id] %>?brand_id=<%= b.id %>">
            <%=h b.name%>
          </a>
        </div>
      </li>
    <% end %>
  </ul>
  <div class="category_list_break"></div>
<% end  %>

<% if @sub_category.length > 0 %>
  <h2 class="category_list_title">按类别选择</h2>
  <ul class="category_list">
    <% for c in @sub_category %>
      <li><a href="/categories/<%=c.id%><%="?brand_id=#{params[:brand_id]}" if params[:brand_id]%>"><%="#{c.name}"%></a></li>
    <%  end %>
  </ul>

<% end  %>


<% if @products %>
  <div class="product_list">
    <ul>
      <% for product in @products %>
        <%= render :partial =>'/products/product_li',:object=>product %>
      <% end %>
    </ul>
  </div>
  <%= will_paginate @products,:prev_label => '«上一页',:next_label => '下一页»' %>
<%end%>


<% if admin? %>
  <div id="admin_action" class="toolbar">
  <span>
    <b>单位:</b>
    <%=  format_unit(@category.unit.to_s) if @category.unit %>
  </span>
  <span>
    <b>导航可见:</b>
    <%=format_boolean @category.show_in_nav %>
  </span>

  <span>
    <b>可用:</b>
    <%=format_boolean @category.active %>
  </span>

  <p>
    <%=form_tag(migrate_product_category_path)%>
    迁移商品至：
    <select id="new_category_id" name="new_category_id">
      <%=  options_for_select categories_options %>
    </select>
    <%= submit_tag "迁移",:confirm =>'确定要迁移商品?'%>
    </form>

  </p>
  <br />
  <%= link_to '编辑', edit_category_path(@category),:class=>'action_edit' %> |
  <%= link_to '类别列表', categories_path,:class=>'action_list' %> |
  <a href="/categories/<%=@category.id%>/products/new" class='action_add'>添加商品</a>
  <%  if @category.children.size > 0 %>
    |
    <a href="/categories/<%=@category.id%>/sort_sub_category" class='action_sort'>子类排序</a>
  <% end %>
  <%  if @category.products.size > 0 %>
    |
    <a href="/categories/<%=@category.id%>/sort_product<%="?brand_id=#{params[:brand_id]}" if params[:brand_id] %>" class='action_sort'>商品排序</a>

    |
    <a href="/products/edit_price?category_id=<%=params[:id]%><%="&brand_id=#{params[:brand_id]}" if @brand%>" class='action_edit'>批量编辑价格</a>

  <% end %>
  <% if @brands %>
    |
    <a href="/categories/<%=@category.id%>/sort_brand" class='action_sort'>品牌排序</a>

  <%end%>
  </div>
<% end %>


<div class="category_list_break"></div>
